package com.wisemoresystem.seal.action.bank;

import java.sql.Time;
import java.util.List;
import java.util.Map;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Scope;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.servlet.ModelAndView;

import com.wisemoresystem.seal.base.action.ProjBaseAction;
import com.wisemoresystem.seal.base.tip.Tip;
import com.wisemoresystem.seal.model.t_bank;
import com.wisemoresystem.seal.model.t_bank_wktime;
import com.wisemoresystem.seal.service.BankService;
import com.wisemoresystem.seal.service.BankWktimeService;
import com.wisemoresystem.seal.util.json.JsonTools;
import com.wisemoresystem.seal.web.WebTools;

/**
 * 机构工作时间
 * 
 * @author Administrator
 *
 */
@Controller("ixBankWktime")
@Scope("prototype")
@RequestMapping("/ix/bank/wktime")
public class BankWktimeAction extends ProjBaseAction {
	@Autowired
	private BankWktimeService wService;
	@Autowired
	private BankService bService;

	/**
	 * 机构工作时间设置
	 * 
	 * @param bank_id
	 * @return
	 */
	@RequestMapping("/list")
	public ModelAndView list(String bank_id) {

		List<Map<String, Object>> bankList = bService.selectBank();
		String bankJson = JsonTools.toJson(bankList);
		List<Map<String, Object>> list = wService.selectBankWktime(bank_id);

		ModelAndView mv = new ModelAndView("/jsp/wktime/bank/list");
		mv.addObject("list", list);
		mv.addObject("bankJson", bankJson);
		mv.addObject("bank_id", bank_id);
		return mv;
	}

	/**
	 * 机构工作时间添加信息
	 * 
	 * @param bank_id
	 * @return
	 */
	@RequestMapping("/add_form")
	public ModelAndView add_form(String bank_id) {

		t_bank bank = wService.findObjById(bank_id, t_bank.class);

		ModelAndView mv = new ModelAndView("/jsp/wktime/bank/add_form");
		mv.addObject("bank", bank);
		return mv;
	}

	/**
	 * 机构工作时间添加
	 * 
	 * @param start_time
	 *            机构工作开始时间
	 * @param end_time
	 *            机构工作结束时间
	 * @param bank_id
	 *            机构id
	 * @return
	 */
	@RequestMapping("/add")
	public ModelAndView add(String start_time, String end_time, String bank_id) {

		t_bank_wktime wk = new t_bank_wktime();
		wk.setUser_id(WebTools.getCurrentUserId());
		wk.setBank_id(bank_id);
		wk.setStart_time(Time.valueOf(start_time));
		wk.setEnd_time(Time.valueOf(end_time));
		wService.saveObj(wk);

		logT.logH("新增机构工作时间", t_bank_wktime.class, wk.get_id());

		super.setTipMsg("保存成功！", Tip.Type.success);
		ModelAndView mv = new ModelAndView("redirect:list.htm");
		mv.addObject("bank_id", bank_id);
		return mv;
	}

	/**
	 * 要修改的机构工作时间信息
	 * 
	 * @param wktime_id
	 * @return
	 */
	@RequestMapping("/edit_form")
	public ModelAndView edit_form(String wktime_id) {

		t_bank_wktime wk = (t_bank_wktime) oc.findObjById(wktime_id,
				t_bank_wktime.class);
		t_bank bank = wService.findObjById(wk.getBank_id(), t_bank.class);

		ModelAndView mv = new ModelAndView("/jsp/wktime/bank/edit_form");
		mv.addObject("wk", wk);
		mv.addObject("bank", bank);
		return mv;
	}

	/**
	 * 机构工作时间修改
	 * 
	 * @param wktime_id
	 *            要修改的机构id
	 * @param start_time
	 *            机构工作时间开始时间
	 * @param end_time
	 *            机构工作时间结束时间
	 * @return
	 */
	@RequestMapping("/edit")
	public ModelAndView edit(String wktime_id, String start_time,
			String end_time) {

		t_bank_wktime wk = (t_bank_wktime) oc.findObjById(wktime_id,
				t_bank_wktime.class);
		wk.setStart_time(Time.valueOf(start_time));
		wk.setEnd_time(Time.valueOf(end_time));
		wService.updateObj(wk);
		logT.logH("修改机构工作时间", t_bank_wktime.class, wk.get_id());

		super.setTipMsg("修改成功！", Tip.Type.success);
		ModelAndView mv = new ModelAndView("redirect:list.htm");
		mv.addObject("bank_id", wk.getBank_id());
		return mv;
	}

	/**
	 * 删除工作时间
	 * 
	 * @param wktime_id
	 *            要修改的机构id
	 * @param bank_id
	 *            机构id
	 * @return
	 */
	@RequestMapping("/del")
	public ModelAndView del(String wktime_id, String bank_id) {

		wService.delObjById(wktime_id, t_bank_wktime.class);
		logT.logH("删除机构工作时间", t_bank_wktime.class, wktime_id);

		super.setTipMsg("删除成功！", Tip.Type.success);
		ModelAndView mv = new ModelAndView("redirect:list.htm");
		mv.addObject("bank_id", bank_id);
		return mv;
	}
}
